package com.sip.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.sip.SipLayer;
import com.sip.db.service.ChannelService;
import com.sip.db.service.DeviceService;

@Configuration
public class SipLayerConfig {

	@Value("${sip.ip}")
	String sipIp;
	@Value("${sip.port}")
	Integer sipPort;
	@Value("${sip.device-id}")
	String sipDeviceId;
	@Value("${sip.domain}")
	String sipDomain;
	@Value("${sip.password}")
	String sipPassword;
	@Value("${media.ip}")
	String mediaIp;
	@Value("${media.port}")
	Integer mediaPort;
	
	@Autowired
	DeviceService deviceService;
	@Autowired
	ChannelService channelService;

	@Bean
	public SipLayer sipLayer(){
		SipLayer sipLayer = new SipLayer(channelService,deviceService, sipIp, sipPort, sipDeviceId, sipDomain, sipPassword, mediaIp, mediaPort);
		boolean startStatus = sipLayer.startServer();
		if(startStatus){
			System.out.println("Sip Server 启动成功 port {"+sipPort+"}");
		}else {
			System.out.println("Sip Server 启动失败");
		}
		return sipLayer;
	}
}